package cn.rkylin.oms.warehouse.stock.controller;

import cn.rkylin.core.controller.ApolloController;
import cn.rkylin.oms.common.utils.LogUtil;
import cn.rkylin.oms.warehouse.stock.service.IStockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * 库存控制类
 *
 * @author liming
 * @date 2017/11/6
 */
@Controller
@RequestMapping("/stock")
public class StockController extends ApolloController {

    @Autowired
    public IStockService stockService;

    @Autowired
    private LogUtil log;

    /**
     * 库存结余接口 http://localhost:8085/OMSJobExecutor/stock/insertStockBalance.action?shopId=01F034521CCB4FCA909C0B4D6DE1297F
     */
    @ResponseBody
    @RequestMapping(value = "/insertStockBalance", method = RequestMethod.GET)
    public Map insertStockBalance(String shopId) throws Exception {
        // shopId,认为是prjId
        String prjId = shopId;
        Map<String, Object> resultMap = new HashMap();
        int effectRows = stockService.insertStockBalance(prjId);
        if (effectRows > 0) {
            resultMap.put("success", "true");
        } else {
            resultMap.put("success", "false");
        }
        return resultMap;
    }
    
    /**
     * 库存差异接口 /stock/generateStockDiff.action?shopId=01F034521CCB4FCA909C0B4D6DE1297F
     */
    @ResponseBody
    @RequestMapping(value = "/generateStockDiff", method = RequestMethod.GET)
    public Map generateStockDiff(String shopId) throws Exception {
        // shopId,认为是prjId
        String prjId = shopId;
        Map<String, Object> resultMap = new HashMap();
        int effectRows = stockService.insertStockDiff(prjId);
        if (effectRows > 0) {
            resultMap.put("success", "true");
        } else {
            resultMap.put("success", "false");
        }
        return resultMap;
    }
}
